﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "WMS_ReturnOrder_D";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<script src="~/Scripts/My97DatePicker/WdatePicker.js"></script>
<div id = "uploadExcel" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false">
<form name = "form1" method="post" id="form1">
    <table>
        <tr>
            <th style="padding:20px;"> Excel：</th>
            <td style="padding:20px;">
                <input name="ExcelPath" type="text" maxlength="255" id="txtExcelPath" readonly="readonly" style="width:200px" class="txtInput normal left">
                <a href = "javascript:$('#FileUpload').trigger('click').void(0);" class="files">@Resource.Browse</a>
                <input class="displaynone" type="file" id="FileUpload" name="FileUpload" onchange="Upload('ExcelFile', 'txtExcelPath', 'FileUpload'); ">
                <span class="uploading">@Resource.Uploading</span>
            </td>
        </tr>
        <tr>
            <th style="padding:20px;"> 导入状态：</th>
            <td style="padding:20px;">
                <label id="importMessage"></label>
                <a id="importResultFile" href="">         点击查看导入结果</a>
            </td>
        </tr>
    </table>
    <div class="endbtndiv">
        <a id = "btnSave" href="javascript:ImportData()" class="easyui-linkbutton btns">直接保存</a>
        <a id = "btnReturn" href="javascript:$('#uploadExcel').window('close')" class="easyui-linkbutton btnc">@Resource.Cancel</a>
    </div>
</form>
</div>
<table style="width:100%">
<tbody>
    <tr>
        <td colspan="4">
            <div class="mvctool">
                <input id="txtReturnOrderNum" type="text" placeholder="退货单号:" class="searchText" />
                <input id="txtInspectBillNum" type="text" placeholder="送检单号:" class="searchText" />
                <input id="txtsupplierShortName" placeholder="供应商简称:" type="text" class="searchText" />
                <input id="txtpartCode" type="text" placeholder="物料编码:" class="searchText" />
                @*退货状态：@Html.DropDownList("txtReturnOrderStatus", ViewBag.ReturnOrderStatus as SelectList, new { @style = "width:70px;" })*@
                退货日期从: <input type="text" id="beginDate" style="width:70px;" value="@(DateTimeHelper.FirstDayOfMonth())" class="wdate" onclick="WdatePicker({startDate:'1980-05-01'})" />
                至: <input type="text" id="endDate" style="width:70px;" value="@(DateTimeHelper.LastDayOfMonth())" class="wdate" onclick="WdatePicker({startDate:'1980-05-01'})" />
                <br>
            </div>
        </td>
    </tr>
    <tr>
        <td style="width:530px;vertical-align: top">
            <div class="mvctool">
                @Html.ToolButton("btnQueryParent", "fa fa-search", Resource.Query, ref perm, "Query", true)
                @Html.ToolButton("btnCreateParent", "fa fa-plus", "库存退货", ref perm, "Create", true)
                @*@Html.ToolButton("btnEditParent", "fa fa-plus", Resource.Edit, ref perm, "Create", true)*@
                @Html.ToolButton("btnDeleteParent", "fa fa-plus", "原始单据失效", ref perm, "Delete", true)
                @Html.ToolButton("btnImportParent", "fa fa-level-down", Resource.Import, ref perm, "Import", true)
                @Html.ToolButton("btnExportTemplateParent", "fa fa-level-up", Resource.ExportTemplate, ref perm, "Export", true)
            </div>
            <table id="ListParent"></table>
        </td>        <td style="width:3px;"></td>
        <td style="vertical-align:top">
            <div class="mvctool">
                @Html.ToolButton("btnPrint", "fa fa-plus", "退货单生成", ref perm, "Create", true)
                @Html.ToolButton("btnConfirm", "fa fa-search", "退货单确认", ref perm, "Check", true)
                @Html.ToolButton("btnDelete", "fa fa-plus", "退货单失效", ref perm, "Delete", true)
                @Html.ToolButton("btnReport", "fa fa-search", "查看单据", ref perm, "Query", true)
            </div>
            <table id="List"></table>
        </td>
    </tr>
</tbody>
</table>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">
    $(function () {
        $('#ListParent').datagrid({
            url: '@Url.Action("GetListParent")',
            width:530,
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'CreateTime',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            onLoadSuccess: function (data) { },
            queryParams: {
                beginDate: $("#beginDate").val(), endDate: $("#endDate").val()
            },
            columns: [[
                { field: 'Id', title: '退货单ID', width: 80,hidden:true },
                { field: 'InspectBillNum', title: '检验单号', width: 120, sortable: true },
                { field: 'PartCode', title: '物料编码', width: 100, sortable: true },
                { field: 'PartName', title: '物料名称', width: 100, sortable: true },
                { field: 'SupplierShortName', title: '供应商', width: 80, sortable: true },
                //{ field: 'InvName', title: '库房', width: 80, sortable: true },
                //{ field: 'Lot', title: '批次号', width: 80,sortable:true },
                { field: 'ReturnQty', title: '应退数', width: 50,sortable:true },
                { field: 'AdjustQty', title: '实退数', width: 50,sortable:true },
                { field: 'Status', title: '单据状态', width: 80,sortable:true },
            ]],
            onClickRow: function (index, row)
            {
                $('#List').datagrid("load", { ParentId: row.Id });
            }
        }).datagrid('getPager').pagination({ showPageList: false, showRefresh: false });

        $('#List').datagrid({
            url: '@Url.Action("GetList")?parentId=-1',
            width:SetGridWidthSub(550),
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'CreateTime',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            onLoadSuccess: function(data) {                @foreach(var r in perm){ if (r.Category == 2) { @Html.Raw("$(this).datagrid('hideColumn','" + r.KeyCode + "'); "); } }
            },
            columns: [[
                { field: 'Id', title: 'Id', width: 80,hidden:true },
                { field: 'HeadId', title: '头表ID', width: 80, hidden: true },
                { field: 'ReturnOrderDNum', title: '退货单号', width: 100, sortable: true },
                { field: 'PartCode', title: '物料代码', width: 60, sortable: true },
                { field: 'ReturnQty', title: '退货数量', width: 40,sortable:true },
                //{ field: 'Remark', title: '备注', width: 80,sortable:true },
                { field: 'PrintStaus', title: '打印状态', width: 50,sortable:true },
                //{ field: 'PrintDate', title: '打印日期', width: 80, sortable: true },
                {
                    field: 'PrintDate', title: '打印日期', width: 40, sortable: true,
                    formatter: function (value, row, index) {
                        return formatterDateNoHour(value);
                    }
                },
                //{ field: 'PrintMan', title: '打印人', width: 80,sortable:true },
                { field: 'ConfirmStatus', title: '确认状态', width: 60,sortable:true },
                //{ field: 'ConfirmMan', title: '确认人', width: 80,sortable:true },
                //{ field: 'ConfirmDate', title: '确认时间', width: 80, sortable: true },
                {
                    field: 'ConfirmDate', title: '确认时间', width: 40, sortable: true,
                    formatter: function (value, row, index) {
                        return formatterDateNoHour(value);
                    }
                },
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
        {
            $("#List,#ListParent").datagrid('load');
        }
        else
        {
            $("#List,#ListParent").datagrid('reload');
        }
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnQueryParent").click(function ()
        {
            var inspectBillNum = $("#txtInspectBillNum").val();
            var supplierShortName = $("#txtsupplierShortName").val();
            var partCode = $("#txtpartCode").val();
            var returnOrderNum = $("#txtReturnOrderNum").val();
            var returnOrderStatus = $("#txtReturnOrderStatus").val();
            if (returnOrderNum == null)
            {
                returnOrderNum = "";
            }
            if (supplierShortName == null)
            {
                supplierShortName = "";
            }
            if (partCode == null)
            {
                partCode = "";
            }
            if (inspectBillNum == null)
            {
                inspectBillNum = "";
            }
            $("#ListParent").datagrid("load", {
                returnOrderNum: returnOrderNum, inspectBillNum: inspectBillNum, supplierShortName: supplierShortName, partCode: partCode, beginDate: $("#beginDate").val(), endDate: $("#endDate").val(), returnOrderStatus: returnOrderStatus
            });
            $("#List").datagrid("load", {
                parentId : -1
            });
        });
        $("#btnCreateParent").click(function () {
            $.modalWindow(Lang.Create, '@Url.Action("CreateParentForDataGrid")', $(window).width() - 50, $(window).height() - 50, 'fa fa-plus');
        });
        $("#btnEditParent").click(function () {
            var row = $('#ListParent').datagrid('getSelected');
            if (row != null) {
                if (row.ConfirmStatus == "已确认") {
                    $.messager.confirm(index_lang_tip, "单据已确认不能被修改")
                }
                else {
                    $.modalWindow(Lang.Edit, '@Url.Action("EditParent")?id=' + row.Id + '&Ieguid=' + GetGuid(), 700, 400, 'fa fa-pencil');
                }

            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }  
        });
        $("#btnDeleteParent").click(function () {
            var row = $('#ListParent').datagrid('getSelected');
            if (row != null) {
                $.messager.confirm(index_lang_tip, CommonLang.YouWantToDeleteTheSelectedRecords, function (r) {
                    if (r) {
	                        $.post("@Url.Action("DeleteParent")?id=" + row.Id, function (data) {
	                            if (data.type == 1)
                                    $("#ListParent").datagrid('load');
	                            $.messageBox5s(Lang.Tip, data.message);
	                        }, "json");
                    }
                });
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });

        $("#btnDelete").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
               $.messager.confirm(index_lang_tip, CommonLang.YouWantToDeleteTheSelectedRecords, function (r) {
                    if (r) {
	                        $.post("@Url.Action("Delete")?id=" + row.Id, function (data) {
	                            if (data.type == 1)
                                    $("#List").datagrid('load');
	                            $.messageBox5s(Lang.Tip, data.message);
	                        }, "json");
                    }
                });
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
	    });

        $("#btnImportParent").click(function() {
            $("#txtExcelPath").val("");
            $("#FileUpload").val("");
            $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 210, iconCls: 'fa fa-level-down' }).window('open');
        });
        $("#btnExportTemplate").click(function() {
            window.location = "@Url.Action("ExportTemplate")";
        });

        $("#btnPrint").click(function() {
            $.modalWindow("单据打印", '@Url.Action("Print")', 1000, 600, 'fa fa-pencil');
        });
        $("#btnConfirm").click(function () {
            $.modalWindow(Lang.Confirm, '@Url.Action("Confirm")', 1000, 600, 'fa fa-plus');
        });
        $("#btnReport").click(function () {             
            var row = $('#List').datagrid('getSelected');

            if (row != null && row.PrintStaus != '无效') {
                if (row.SupplierCode == "S210") {
                //库存退货单打印
                    $.modalWindow("单据打印", '@Url.Action("ShowBill", "ReportManager", new { area = "Report" })?reportCode=InvReturnOrder&BillNum=' + row.ReturnOrderDNum + '&Ieguid=' + GetGuid(), 1000, 600, 'fa fa-pencil');}
                else {
                //送检退货单打印
                $.modalWindow("单据打印", '@Url.Action("ShowBill", "ReportManager", new { area = "Report" })?reportCode=ReturnOrder&BillNum=' + row.ReturnOrderDNum + '&Ieguid=' + GetGuid(), 1000, 600, 'fa fa-pencil');}
                
            } else { $.messageBox5s(Lang.Tip, '请选择有效单据'); }
            $('#List').datagrid('clearSelections');
        });
    });
    function ImportData()
    {
        showLoading();
        var url = "@Url.Action("ImportParent")?filePath="+$("#txtExcelPath").val();
        $.post(url, function(data) {
            if (data.type == 1)
            {
             $("#List").datagrid('load');
             $('#uploadExcel').window('close');
             $('#FileUpload').val('');
            }
            hideLoading();
            $.messageBox5s('提示', data.message);
            $('#importMessage').html(data.message);
            $('#importResultFile').attr('href', data.value); 
        }, "json");
    }
    function resizeLayout()
     {
         setTimeout(function () {
             $('#ListParent').datagrid('resize', {
             }).datagrid('resize', {
                 height: SetGridHeightSub(45)
             });
             $('#List').datagrid('resize', {
             }).datagrid('resize', {
                 width: $(window).width() - 450,
                 height: SetGridHeightSub(45)
             });
         },100);
	    }
</script>

